﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

public partial class GiaoDienClient_TrangTimMaHS : System.Web.UI.Page
{
    SoLienLacDataContext db = new SoLienLacDataContext();
    clsLoadCombobox cls=new clsLoadCombobox();
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            cls.LoadComboboxNamHoc(drNamHoc1);
            cls.LoadComboboxNamHoc(drNamHoc);
            cls.LoadComboboxKhoi(drKhoiHoc);
            cls.LoadComboboxLopTheoKhoi(drLopHoc,int.Parse(drKhoiHoc.SelectedValue.ToString()));
            //cls.LoadDropHS(drTenHS,int.Parse(drNamHoc.SelectedValue.ToString()),int.Parse(drLopHoc.SelectedValue.ToString()));
        }
    }
    private void LoadGrid(int manam,int malop)
    {
        grvDSHS.DataSource = db.funcTraVeThongTinHSTrongLop(manam, malop);
        grvDSHS.DataBind();
    }
    protected void btnTimKiem_Click(object sender, EventArgs e)
    {
        int manam = int.Parse(drNamHoc.SelectedValue.ToString());
        int malop = int.Parse(drLopHoc.SelectedValue.ToString());
        if (rdoXemTheoLop.Checked == true)
        {
            LoadGrid(manam, malop);
        }
        
    }
    protected void drLopHoc_SelectedIndexChanged(object sender, EventArgs e)
    {
        
        //cls.LoadDropHS(drTenHS, int.Parse(drNamHoc.SelectedValue.ToString()), int.Parse(drLopHoc.SelectedValue.ToString()));
    }
    protected void drKhoiHoc_SelectedIndexChanged(object sender, EventArgs e)
    {
        cls.LoadComboboxLopTheoKhoi(drLopHoc, int.Parse(drKhoiHoc.SelectedValue.ToString()));
        //cls.LoadDropHS(drTenHS, int.Parse(drNamHoc.SelectedValue.ToString()), int.Parse(drLopHoc.SelectedValue.ToString()));
    }
    protected void rdoXemCaNhan_CheckedChanged(object sender, EventArgs e)
    {
        mulXemDiem.ActiveViewIndex = 0;
    }
    protected void rdoXemTheoLop_CheckedChanged(object sender, EventArgs e)
    {
        mulXemDiem.ActiveViewIndex = 1;
    }
    protected void btnXem_Click(object sender, EventArgs e)
    {
        bool kt = true;
        kt = kiemtratext();
        if (kt == false)
        { return; }
        if (rdoXemCaNhan.Checked == true)
        {
            Response.Redirect("TrangThongTinChiTietDiem.aspx?MaHS=" + txtMaHS.Text + "&MaNam=" + this.drNamHoc.SelectedValue.ToString());
        }
        if (rdoXemtheoTen.Checked == true)
        {
            grvDSHS.DataSource = db.funcTimKiemHocSinh(int.Parse(this.drNamHoc.SelectedValue.ToString()), txtMaHS.Text);
            grvDSHS.DataBind();
        }
    }
    bool kiemtratext()
    {
        bool kt = true;
        lblThongBao.InnerText = "";
        if (txtMaHS.Text == ""&&rdoXemCaNhan.Checked==true)
        {
            lblThongBao.InnerText = "*";
            kt = false;
        }
        if (txtMaHS.Text != "" && rdoXemCaNhan.Checked == true)
        {
            var c = from p in db.HocSinhs where p.MaHS == txtMaHS.Text select p.MaHS;
            if (c.Count() == 0)
            {
                lblThongBao.InnerText = "Mã không tồn tại";
                txtMaHS.Text = "";
                kt = false;
            }
        }
        return kt;
    }
    protected void rdoXemtheoTen_CheckedChanged(object sender, EventArgs e)
    {
        mulXemDiem.ActiveViewIndex = 0;
        lblMaHS.Text = "Tên học sinh:";
    }
}